<?php
namespace app\admin\model;

use think\captcha\Captcha;
use think\Model;

class Login extends Model
{
    public function juedgeParam($data)
    {
        $username = $data['username'];
        $password = $data['password'];
        $code = $data['code'];
        $captcha = new Captcha();
        $code_result = $captcha->check($code);
        if (!$code_result) {
            return 4;
        }
        $result = db('admin')->where('username', $username)->find();
        if ($result) {
            $result_password = $result['password'];
            if (md5($password) == $result_password) {
                // 登录成功
                session('username', $username);
                session('uid', $result['id']);
                return 3;
            } else {
                // 密码不对
                return 2;
            }
        } else {
            // 用户名不正确
            return 1;
        }

    }
}
